package com.mvvm.ktnet.base.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.mvvm.ktnet.databind.livedata.event.EventLiveData
import java.io.Closeable


/**
 * 作者　: Alex
 * 时间　: 2019/12/12
 * 描述　: ViewModel的基类 使用ViewModel类，放弃AndroidViewModel，原因：用处不大 完全有其他方式获取Application上下文
 */
open class BaseViewModel : ViewModel(), Closeable {

    val loadingChange: UiLoadingChange by lazy { UiLoadingChange() }

    inner class UiLoadingChange {
        val showDialog by lazy {
            MutableLiveData<LoadingDialogEntity>()
        }

        val showPageLoad by lazy {

            MutableLiveData<LoadingPageEntity>()

        }

    }

    val loadStatus: LoadStatus by lazy { LoadStatus() }

    inner class LoadStatus {
        val loadEmpty by lazy { EventLiveData<LoadStatusBean>() }
        val loadError by lazy { EventLiveData<LoadStatusBean>() }
        val loadFinally by lazy { EventLiveData<LoadFinally>() }
    }

    override fun close() {

    }
}


enum class LoadingType {
    LOADING_NULL, LOADING_PAGE, LOADINGDIALOG
}

data class LoadingDialogEntity(
    var loadingType: LoadingType = LoadingType.LOADING_NULL,
    var loadString: String = "",
    var dismissDialog: Boolean = true,
)

data class LoadingPageEntity(
    var loadingType: LoadingType = LoadingType.LOADING_NULL,
    var loadString: String = "",
    var show:Boolean=false,
    var empty: Boolean = false,
    var error:Boolean=false
)



data class LoadStatusBean(var mathCode: Int, var throwable: Throwable)
data class LoadFinally(var mathCode: Int)